﻿using System;
using System.Text;
using Kugar.Core.Network;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Kugar.Tool.DataSync
{
    /// <summary>
    /// 面向Http的传输接口
    /// </summary>
    public interface IHttpTransferPlugin : ITransferPlugin
    {
        string Url { set; get; }

        Func<JObject, string> Encryption { set; get; }

        Encoding Encoding { set; get; }
    }

    public class HttpTransferPlugin : IHttpTransferPlugin
    {
        public void Send(JObject data)
        {
            WebHelper.GetUriDataByPost(Url, data.ToString(Formatting.None), "", this.Encoding);
        }

        public string Url { set; get; }

        public Func<JObject, string> Encryption { get; set; }

        public Encoding Encoding { get; set; }=Encoding.UTF8;
    }
}